<?php

namespace app\admin\middleware;
use think\facade\View;

/**
 * 后台登录
 * Class Auth
 * User:于小涛
 * Date:2020/2/16
 * Time:16:06
 */
class AuthLoginMiddleware
{
    private $arr_exclude=array(
        'adminlogin',''
    );
    public function handle($request, \Closure $next)
    {
        $str_path_info=$request->pathinfo();
        $str_path_info=strtolower($str_path_info);
        $arr_admin_info=session('admin');
        if (!in_array($str_path_info,$this->arr_exclude)) {
            if(empty($arr_admin_info)){
                if ($request->isAjax()) {
                    return output_data(array(), 'admin-auth-checktokenerror');
                } else {
                    return redirect("/admin?js=<script>window.top.location.href='/admin';</script>");
                }
            }
        }
        View::assign('arr_admin_info',$arr_admin_info);
        View::assign('request',$request);
        return $next($request);
    }
}
